package com.hex.liyue.usermodule.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hex.liyue.LiYueApplication;
import com.hex.liyue.R;
import com.hex.liyue.commonmodule.glide.GlideCircleTransform;
import com.hex.liyue.commonmodule.utils.DateUtils;
import com.hex.liyue.usermodule.bean.MyFriendsResultBean;

import java.util.List;

/**
 * Created by WJ on 2016/6/12.
 */
public class AdapterFriends extends RecyclerView.Adapter<AdapterFriends.MyHolder> {
    private List<MyFriendsResultBean.DataBean.MatesBean> list;

    public void setList(List<MyFriendsResultBean.DataBean.MatesBean> list) {
        this.list = list;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.item_friends, null);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(MyHolder holder, int position) {
        MyFriendsResultBean.DataBean.MatesBean matesBean = list.get(position);
        Glide.with(LiYueApplication.getInstance())
                .load("")
                .error(R.drawable.default_error_image)
                .transform(new GlideCircleTransform(LiYueApplication.getInstance()))
                .into(holder.iv_avater);
        holder.tv_myfriends_name.setText(matesBean.nickname);
        holder.tv_myfriends_date.setText(DateUtils.getFormatDate(matesBean.invite_time * 1000, "yyyy-MM-dd HH:mm:ss") + "注册上线");
    }

    @Override
    public int getItemCount() {
        if (list == null) {
            return 0;
        } else {
            return list.size();
        }
    }


    class MyHolder extends RecyclerView.ViewHolder {
        public ImageView iv_avater;
        public TextView tv_myfriends_name;
        public TextView tv_myfriends_date;

        public MyHolder(View itemView) {
            super(itemView);
            iv_avater = (ImageView) itemView.findViewById(R.id.iv_avater);
            tv_myfriends_name = (TextView) itemView.findViewById(R.id.tv_myfriends_name);
            tv_myfriends_date = (TextView) itemView.findViewById(R.id.tv_myfriends_date);
        }

    }
}
